#!/bin/bash
# generate-git-patch.sh old.file new.file name.path

# leo@leo ~/data_4t/github/lotus_bsp/buildroot/output/build
# $ ../../../scripts/generate-git-patch.sh host-fakeroot-1.20.2.org/libfakeroot.c host-fakeroot-1.20.2/libfakeroot.c 0005.fix-glibc-compatibility.patch

PATCH_FILE="$3"
ORIG_FILE="$1"
MODIFIED_FILE="$2"
AUTHOR_NAME="lotus"
AUTHOR_EMAIL="lotus@example.com"

# 生成diff内容
DIFF_CONTENT=$(diff -burN "$ORIG_FILE" "$MODIFIED_FILE")

# 生成patch文件
cat > "$PATCH_FILE" << EOF
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: $AUTHOR_NAME <$AUTHOR_EMAIL>
Date: $(date +"%a, %d %b %Y %H:%M:%S %z")
Subject: [PATCH] xxxxxxxxxxxxxxxxxxx

This patch resolves compilation issues with newer glibc versions
by providing proper _STAT_VER definitions based on architecture.

Signed-off-by: $AUTHOR_NAME <$AUTHOR_EMAIL>
---
EOF

echo "$DIFF_CONTENT" >> "$PATCH_FILE"
echo "-- " >> "$PATCH_FILE"
echo "2.25.1" >> "$PATCH_FILE"

echo "Generated git-compatible patch: $PATCH_FILE"
